package com.demo.exception;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @name: 李佳
 * @data: 2022/6/13 10:54
 * @className: GlobalException
 * @author: LiJia
 **/
public class GlobalException extends Throwable{

    /**
     * 日志
     * @return 日志
     */
    public static Logger getLogger() {
        return LoggerFactory.getLogger(GlobalException.class);
    }

    /**
     * 自定义全局异常 可以根据不同业务抛出相应异常
     * @param val 异常信息
     * @throws Throwable 抛出异常结束
     */
    public GlobalException(String val) throws Throwable{
        GlobalException.getLogger().error(val);
        throw new Throwable();
    }

    public static void sqlException(String msg){
        GlobalException.getLogger().error(msg);
    }

    /**
     * 参数问题
     * @param msg 消息
     */
    public static void paramException(String msg){
        GlobalException.getLogger().error(msg);
    }

    /**
     * redis 存取失败
     * @param exception 异常
     * @param msg 信息
     * @throws Exception exception
     */
    public static void redisException(Exception exception,String msg) throws Exception {
        GlobalException.getLogger().error("redis:"+msg);
        GlobalException.getLogger().error("redis"+exception.getMessage());
        throw new Exception(exception);
    }


    public static void rabbitMq(Exception exception,String msg) throws Exception {
        GlobalException.getLogger().error("rabbit send fail:"+msg);
        GlobalException.getLogger().error("rabbit fail:"+exception.getMessage());
        throw new Exception(exception);
    }
}
